package com.act.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import com.act.dao.IPerformanceEvaluationDao;
import com.act.domain.PerformanceEvaluation;
import com.act.dto.PagerDTO;
import com.act.service.api.IPerformanceEvaluationService;
import com.act.vo.PagerVo;

@Service
public class PerformanceEvaluationService implements IPerformanceEvaluationService{
	
	@Resource
	IPerformanceEvaluationDao performanceEvaluationDao;
	
	@Override
	public PerformanceEvaluation getById(@Param("id")int id) {
		return performanceEvaluationDao.getById(id);
	}

	@Override
	public void add(PerformanceEvaluation performanceEvaluation) {
		performanceEvaluationDao.add(performanceEvaluation);
	}

	@Override
	public void update(PerformanceEvaluation performanceEvaluation) {
		performanceEvaluationDao.update(performanceEvaluation);
	}

	@Override
	public void delete(int id) {
		performanceEvaluationDao.delete(id);
	}


	@Override
	public PagerVo<Map> getAll(@Param("pagerDTO")PagerDTO pagerDTO) {
		int startIndex = pagerDTO.getStartIndex();
		int endIndex = pagerDTO.getEndIndex();
		int totalCounts = performanceEvaluationDao.getCounts(null,2);
		List<Map> list = performanceEvaluationDao.getAll(startIndex, endIndex);
		PagerVo<Map> pagerVo = new PagerVo<>(pagerDTO.getPageIndex(),pagerDTO.getPageSize(),totalCounts,list);
		
		return pagerVo;
	}

	@Override
	public PagerVo<Map> getByJobnumOrState(@Param("deal_status") int deal_status,@Param("jobnum") String jobnum,@Param("pagerDTO")PagerDTO pagerDTO) {
		int startIndex = pagerDTO.getStartIndex();
		int endIndex = pagerDTO.getEndIndex();
		int totalCounts = performanceEvaluationDao.getCounts(jobnum,deal_status);
		List<Map> list = performanceEvaluationDao.getByJobnumOrState(deal_status, jobnum, startIndex, endIndex);
		PagerVo<Map> pagerVo = new PagerVo<>(pagerDTO.getPageIndex(),pagerDTO.getPageSize(),totalCounts,list);
		
		return pagerVo;
	}
}
